package netty.executor;

import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.HashedWheelTimer;
import org.apache.lucene.util.NamedThreadFactory;

import java.util.concurrent.TimeUnit;

public class HashedWheelTimerZetas {


    public void start() throws InterruptedException {
        EmbeddedChannel session = new EmbeddedChannel();

        NamedThreadFactory namedThreadFactory = new NamedThreadFactory("TW");
        HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(
                namedThreadFactory,
                1, TimeUnit.MILLISECONDS,
                1, false);

        for (int i = 0; i < 10; i++) {
            int finalI = i;
            long now = System.nanoTime();
            hashedWheelTimer.newTimeout(timeout -> {
                session.flush();
                System.out.println("task :" + finalI + ":" + (System.nanoTime() - now));
            }, 1, TimeUnit.MICROSECONDS);
        }

        Thread.sleep(3000);

        hashedWheelTimer.stop();
    }

    public static void main(String[] args) throws InterruptedException {
        new HashedWheelTimerZetas().start();
    }

}
